package com.zhiyou100.servlet;

import com.zhiyou100.dao.StudentDao;
import com.zhiyou100.entity.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 获取所有的学生
 *
 * @author yang
 * @version 1.0.0
 * @date 2020-09-15 17:01
 */
@WebServlet(name = "StudentGetList", urlPatterns = "/student/getList")
public class StudentGetList extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        final StudentDao dao = new StudentDao();
        final List<Student> students = dao.listStudent();
        req.setAttribute("list", students);
        req.getRequestDispatcher("/index.jsp").forward(req, resp);
    }
}
